"""
makey piano 2.0
experiment for code to play the piano
last edited at 2018-9-21
by Stone, GDOU-ASTI
"""
import pygame,sys
import os

pygame.init()
pygame.mixer.init()
src = pygame.display.set_mode([800,600])
pygame.time.delay(1000)

path = '1760'
n1 = pygame.mixer.Sound(os.path.join(path, '1.wav'))
n2 = pygame.mixer.Sound(os.path.join(path, '2.wav'))
n3 = pygame.mixer.Sound(os.path.join(path, '3.wav'))
n4 = pygame.mixer.Sound(os.path.join(path, '4.wav'))
n5 = pygame.mixer.Sound(os.path.join(path, '5.wav'))
n6 = pygame.mixer.Sound(os.path.join(path, '6.wav'))
n7 = pygame.mixer.Sound(os.path.join(path, '7.wav'))

notemap = {0:n1, 1:n1,2:n2,3:n3,4:n4,5:n5,6:n6,7:n7}

notes = [
6, 3, 3, 3, 3, 2,
1, 2, 1, 0, -1,
6, 6, 6, 6, 6, 5,
3, 5, 5, 4, 3,

3, 6, 6, 5, 3, 2,
1, 2, 1, 0, -1, -4,
-4, 1,1, 0, -1, 3,
2, 1, 0, -2,
-1

]


#1 = 1 pat
durt = [
0.5, 0.5, 0.5, 0.5, 1.5, 0.5,
0.75, 0.25, 0.5, 0.5, 2,
0.5, 0.5, 0.5, 0.5, 1.5, 0.5,
0.5, 0.5, 0.5, 0.5, 2,

0.5, 0.5, 0.5, 0.5, 1.5, 0.5,
0.75, 0.25, 0.5, 0.5, 1, 1,
0.5, 0.5, 0.5, 0.5, 1.5, 0.5,
0.5, 0.5, 0.5, 0.5,
2
]


length = len(notes)
if len(durt) != length:
    print 'error:not equal length!!!'
    sys.exit()
    
for idx in range(length):
    print 'idx:',idx,
    print 'note:',notes[idx],
    print 'duration',durt[idx]
    notemap[notes[idx]].play()
    pygame.time.delay(int(500*durt[idx]))
        


print 'program done'

